package com.whp.yky.yky.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.whp.yky.yky.entity.Storeroom;
import com.whp.yky.yky.mapper.StoreroomMapper;
import com.whp.yky.yky.service.StoreroomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whp
 * @since 2021-03-12
 */
@Service
public class StoreroomServiceImpl extends ServiceImpl<StoreroomMapper, Storeroom> implements StoreroomService {

    @Autowired
    private StoreroomMapper storeroomMapper;

    @Override
    public IPage<Storeroom> getStoreroomInfo(IPage<Storeroom> page, Storeroom storeroom) {
        return page.setRecords(storeroomMapper.getStoreroomInfo(page,storeroom));
    }

    @Override
    public boolean insertStoreroomInfo(Storeroom storeroom) {
        try {
            int effecteNum= storeroomMapper.insertStoreroomInfo(storeroom);
            if(effecteNum>0){
                //如果影响行数大于0，那么就是增加成功
                System.out.println("增加成功，主键为："+storeroom.getId());
                return true;
            }else {
                throw  new RuntimeException("插入信息失败,插入行数有误");
            }
        }catch (Exception e){
            throw  new RuntimeException("插入信息失败了:"+e.getMessage());
        }
    }

    @Override
    public boolean updateStoreroomInfo(Storeroom storeroom) {
        if (storeroom.getId()!= 0&&!"".equals(storeroom.getId())){
            try {
                int effecteNum= storeroomMapper.updateStoreroomInfo(storeroom);
                if(effecteNum>0){
                    //如果影响行数大于0，那么就是增加成功
                    System.out.println("修改成功，主键为："+storeroom.getId());
                    return true;
                }else {
                    throw  new RuntimeException("修改失败,插入行数有误");
                }
            }catch (Exception e){
                throw  new RuntimeException("修改失败:"+e.getMessage());
            }
        }else{
            throw new RuntimeException("信息不能为空！！！！");
        }
    }
}
